package view1;

import com.ny.entity.Manager;
import com.ny.entity.Student;
import service.StudentService;
import service.StudentServiceImpl;

import java.sql.SQLException;
import java.util.Scanner;

public class ViewMain {
    public static void main(String[] args) throws SQLException, ClassNotFoundException {
        StudentService service = new StudentServiceImpl();
        Student student = new Student();
        Manager manager = new Manager();
        System.out.println("欢迎来到校园商品售卖管理系统");
        boolean flag = true;
        while (flag){
            System.out.println("1.注册账号");
            System.out.println("2.登录账号");
            System.out.println("3.管理员登陆账号");
            System.out.println("4.退出系统");
            System.out.println("请输入你的选择：");
            Scanner scanner = new Scanner(System.in);
            int choice = scanner.nextInt();
            switch (choice) {
                case 1:
                    System.out.println("欢迎来到注册系统");
                    System.out.println("请输入用户名");
                    String username = scanner.next();
                    System.out.println("请输入密码");
                    String password = scanner.next();
                    System.out.println("请输入手机号");
                    String phone = scanner.next();
                    student.setStudentName(username);
                    student.setStudentPassword(password);
                    student.setStudentPhone(phone);
                    int add = service.add(student);
                    if (add>0){
                        System.out.println("注册成功");
                    }else {
                        System.out.println("注册失败");
                    }
                    break;
                    case 2:
                        System.out.println("用户登录");
                        System.out.println("请输入用户名");
                        String studentName = scanner.next();
                        System.out.println("请输入密码");
                        String studentPassword = scanner.next();
                        // 调用业务层的登录功能：
                        student= service.login(studentName, studentPassword);
                        if(student != null){
                            System.out.println("登录成功");
                            IndexLogin indexLogin = new IndexLogin();
                            indexLogin.indexLogin(student);
                        }
                        else {
                            System.out.println("登录失败");
                        }
                    break;
                    case  3:
                        System.out.println("请输入用户名");
                        String managername1 = scanner.next();
                        System.out.println("请输入密码");
                        String managerpwd1 = scanner.next();
                        manager.setManagerName(managername1);
                        manager.setManagerPassword(managerpwd1);
                        int add1 = service.add(manager);
                      break;
                      case 4:
                        flag = false;
                        System.out.println("已退出");
                        break;
                        }
            }
        }
    }

